package com.example.havi.bean;

import android.text.TextUtils;

import com.example.havi.helper.MessageTypes;

import java.util.HashMap;
import java.util.Map;

public class MessageBean {
    //自己信息
    private String userId;
    private String chatId;
    private String nickName;
    private String avatar;

    //对方信息
    private String toUserId;
    private String toNickName;
    private String toAvatar;

    //群信息
    private String groupAvatar;
    private String groupName;

    //自定义消息
    private String customMessageType;   //自定义消息类型 MessageTypes.BASIC_MESSAGE 0:文本类型   MessageTypes.CARD_MESSAGE 1:名片类型

    //...新增属性时要在 beanToMap() mapToBean() 方法更新配置 否则新增的属性不能显示

    public String getCustomMessageType() {
        return customMessageType == null ? MessageTypes.BASIC_MESSAGE: customMessageType;
    }

    public void setCustomMessageType(String customMessageType) {
        this.customMessageType = customMessageType;
    }

    public String getToUserId() {
        return toUserId;
    }

    public void setToUserId(String toUserId) {
        this.toUserId = toUserId;
    }


    public String getToNickName() {
        return toNickName;
    }

    public void setToNickName(String toNickName) {
        this.toNickName = toNickName;
    }

    public String getToAvatar() {
        return toAvatar;
    }

    public void setToAvatar(String toAvatar) {
        this.toAvatar = toAvatar;
    }

    public String getGroupAvatar() {
        return groupAvatar == null ? "" : groupAvatar;
    }

    public void setGroupAvatar(String groupAvatar) {
        this.groupAvatar = groupAvatar;
    }

    public String getGroupName() {
        return groupName == null ? "" : groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getUserId() {
        return userId == null ? "" : userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getChatId() {
        return chatId == null ? "" : chatId;
    }

    public void setChatId(String chatId) {
        this.chatId = chatId;
    }

    public String getNickName() {
        return nickName == null ? "" : nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getAvatar() {
        return avatar == null ? "" : avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }



    public Map<String,String> beanToMap(){
        Map<String,String> params= new HashMap<>();
        params.put("userId",userId);
        params.put("chatId",chatId);
        params.put("nickName",nickName);
        params.put("avatar",avatar);

        params.put("toUserId",toUserId);
        params.put("toNickName",toNickName);
        params.put("toAvatar",toAvatar);

        params.put("groupAvatar",groupAvatar);
        params.put("groupName",groupName);

        params.put("customMessageType",customMessageType);
        return params;
    }

    public static MessageBean mapToBean(Map<String,Object> map) {
        MessageBean bean = new MessageBean();
        bean.setUserId(map.get("userId")+"");
        bean.setChatId(map.get("chatId")+"");
        bean.setNickName(map.get("nickName")+"");
        bean.setAvatar(map.get("avatar")+"");

        bean.setToUserId(map.get("toUserId")+"");
        bean.setToNickName(map.get("toNickName")+"");
        bean.setToAvatar(map.get("toAvatar")+"");

        bean.setGroupAvatar(map.get("groupAvatar")+"");
        bean.setGroupName(map.get("groupName")+"");

        if(map.containsKey("customMessageType")){
            String customMessageType = (String) map.get("customMessageType");
            if(TextUtils.isEmpty(customMessageType)){
                bean.setCustomMessageType(MessageTypes.BASIC_MESSAGE);
            }else{
                bean.setCustomMessageType(customMessageType);
            }
        }else{
            bean.setCustomMessageType(MessageTypes.BASIC_MESSAGE);
        }

        return bean;
    }
}
